package com.neusoft.service.Impl;

import java.sql.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.mapper.CalendarMapper;
import com.neusoft.po.CalendarPO;
import com.neusoft.service.CalendarService;
import com.neusoft.util.DateUtil;
import com.neusoft.vo.CalendarVO;


@Service
public class CalendarServiceImpl implements CalendarService {

	@Autowired
	private CalendarMapper mapper;

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public List<CalendarPO> getCalendar(Integer year) {
		// 根据年份拼接出字符串，并转为sql.Date进行查询
		String start = year + "-01-01";
		String end = year + "-12-31";
		Date d1 = DateUtil.string2SqlDate(start);
		Date d2 = DateUtil.string2SqlDate(end);
		
		// 接收数据
		CalendarVO vo = new CalendarVO();
		vo.setStart(d1);
		vo.setEnd(d2);
		List<CalendarPO> res = mapper.getCalendar(vo);
		
		//若该年度暂无数据，则生成该年度的默认日历并返回
		if(res.isEmpty() || res == null) {
			Integer n = mapper.GenerateCalendar(year);
		}
		return res;
	}

	@Override
	public Integer updateCalendar(CalendarPO po) {
		return mapper.updateCalendar(po);
	}

}
